package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    //今日新增或注册用户数量
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{today} AND TYPE = #{type}")
    Integer findTodayRegistOrLoginCount(@Param("today") String today,@Param("type") String type);

    //今日活跃用户数量
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{today}")
    Integer findTodayActiveCount(String today);

    //次日留存用户数量
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{today} AND user_id IN " +
            "(SELECT user_id FROM tb_log WHERE log_time = #{yesterday} AND TYPE = '0102')")
    Integer findRetention1dCount(@Param("today") String today,@Param("yesterday") String yesterday);

}